#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：图灵学习 
@File    ：10.使用mongodb保存数据.py
@IDE     ：PyCharm 
@Author  ：ChenLiGao
@Date    ：2024-12-03 14:41
'''
import pymongo

client_mongo = pymongo.MongoClient(host="localhost", port=27017)
db = client_mongo["py_spider"]['stu_info']

# # 插入单条数据
# student = {"id":"2024101","name":"张三","age":18,"address":"北京"}
# res = db.insert_one(student)
# print(res)


# 插入多条数据
students = [
    {"id":"2024102","name":"李四","age":19,"address":"上海"},
    {"id":"2024103","name":"王五","age":20,"address":"广州"},
    {"id":"2024104","name":"赵六","age":21,"address":"深圳"}
]

db.insert_many(students)